//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package api_common

import (
	"context"

	"gitcode.com/eteam/api-server/dao/board_dao"
	"gitcode.com/eteam/api-server/dao/fs_dao"
	"gitcode.com/eteam/proto-gen-go.git/fs_api"
)

/*
 * 创建画板
 * 1. 创建画板信息
 */

func CreateBoard(ctx context.Context, boardInfo *board_dao.BoardInfoDbItem, memberUserId string) error {
	//创建画板图片存储
	err := fs_dao.FsInfoDao.Insert(ctx, &fs_dao.FsInfoDbItem{
		FsId:      boardInfo.ImageFsId,
		OwnerType: fs_api.FS_OWNER_TYPE_FS_OWNER_TYPE_BOARD,
		OwnerId:   boardInfo.BoardId,
		Status: fs_dao.FsStatusDbItem{
			FileCount:     0,
			TotalFileSize: 0,
		},
		MaxFilecount: 0,
		MaxTotalSize: 0,
		LastGcTime:   0,
	})
	if err != nil {
		return err
	}
	//创建画板信息
	err = board_dao.BoardInfoDao.Insert(ctx, boardInfo)
	if err != nil {
		return err
	}
	//加入画板
	err = JoinBoard(ctx, &board_dao.MemberInfoDbItem{
		MemberUserId: memberUserId,
		BoardId:      boardInfo.BoardId,
		LastViewTime: boardInfo.CreateTime,
		CreateTime:   boardInfo.CreateTime,
		Admin:        true,
	})
	if err != nil {
		return err
	}

	return nil
}
